package com.qf.smsplatform.service.impl;

import com.qf.smsplatform.service.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Set;

@Service
public class RedisCacheServiceImpl implements CacheService {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void hMSet(String key, Map map) {
        redisTemplate.opsForHash().putAll(key,map);
    }

    @Override
    public Map hGetAll(String key) {
        return redisTemplate.opsForHash().entries(key);
    }

    @Override
    public Object hGet(String key, String field) {
        return redisTemplate.opsForHash().get(key,field);
    }

    @Override
    public void saveCache(String key, String value) {
        redisTemplate.opsForValue().set(key,value);
    }

    @Override
    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    @Override
    public void sadd(String key, Map map) {
        redisTemplate.opsForSet().add(key,map);
    }

    @Override
    public Set<Object> smembers(String key) {
        return redisTemplate.opsForSet().members(key);
    }

    @Override
    public void saddString(String key, String[] values) {
        redisTemplate.opsForSet().add(key,values);
    }

    @Override
    public Long hincr(String key, String field, long value) {
        return redisTemplate.opsForHash().increment(key,field,value);
    }
}
